Bitcoin Minner

Based on the LSP protocol, in this project, we built a server that can assign tasks to the miner, and solve the Bitcoin task using the distributed system advantage. Before you read this blog, you should first know the our last project LSP protocol.

LSP Project
Implement the Live Sequence Protocol (LSP) is a homegrown protocol for providing reliable communication with simple client and server APIs on top of the Internet UDP protocol. In this project of Go language, we implement
https://58191554.github.io/distributedSys/LSP%20Project%201133c7b389eb80a5b580fd5a335dce20.html

System Design

There are 3 kind of usr in this project:

The easiest is the client. The client only need to request for a bitcoin nonce, and the message attached. Then it wait for the server report the answer, and close the request.

The Miner has 2 behaviors:

The Server connects clients and miners. It can handle tasks from clients, and divide the task into small jobs for the miner. It need handle the client failure, and miner failure. When the client request a task, the server will divide it into small chunks and wait for free miner to handle the jobs. For example, if the nonce is 0-9999, the job can be 0-999, 1000-1999, … 9900-9999.

The server uses a scheduler to manage the order of tasks. We used the Shortest Remaining Time First algorithm to improve efficiency and fairness. When take a task from client, we will compute the remaining time of it, and maintain a priority queue. When a job finished, a free miner will appear with the complete job. The scheduler will first update the remaining time of the task, and update the position of the task in the priority queue. Then we will pop the first task in the queue, and assign the job to the free miner. The job just assigned will be removed from a job set of the task. When a miner failed to connect the server, the server will put the job assign to the miner back to the job set. If the job is done successfully, and it is the last job needed to be done, the server will remove the task from the task queue, and return the answer to the client.